-- Viral Resistance - T-Engine 4 Module
-- Copyright (C) 2010 Mikolai Fajer
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program.  If not, see <http://www.gnu.org/licenses/>.
--
-- Mikolai Fajer "yufra"
-- mfajer@gmail.com

newChat{ id="welcome",
	text = [[#LIGHT_GREEN#The large #RED#red button#LIGHT_GREEN# that will initiate the biohazard lockdown sits at chest level in the wall.]],
	answers = {
		{"Push it.", jump="lockdown",
			cond=function(npc, player) return player:isQuestStatus("code_green", engine.Quest.PENDING, "lockdown") end,
			action=function(npc, player)
				player:setQuestStatus("code_green", engine.Quest.COMPLETED, "lockdown")
				player:setQuestStatus("code_green", engine.Quest.PENDING, "escape")
				player:hasQuest("code_green"):lock_outer_ward()
				player:newEffect{name="INNER_LOCKDOWN_COUNTDOWN", desc=[[]], type="countdown",
					on_lose = function(self, err)
						local chat = engine.Chat.new("lockdown", npc, player)
						chat:invoke("decontamination")
					end,
				}
				player:setEffect(player.EFF_INNER_LOCKDOWN_COUNTDOWN, 5, {})
			end,
		},
		{"Walk away.",},
	}
}

newChat{ id="lockdown",
	text = [[#RED#Red lights begins flashing#LIGHT_GREEN# as you punch the button, and the PA system kicks in.  #WHITE#"Lockdown initiated in the Biohazard Ward.  Inner doors close in five seconds."]],
	answers = {
		{"Step away."}
	}
}

newChat{ id="auto_lockdown",
	text = [[#RED#Red lights begins flashing#LIGHT_GREEN# and the PA system kicks in.  #WHITE#"Lockdown initiated in the Biohazard Ward.  Inner doors close in ten seconds."]],
	answers = {
		{"Continue.", action=function(npc, player)
			player:setQuestStatus("code_green", engine.Quest.FAILED, "lockdown")
			player:setQuestStatus("code_green", engine.Quest.PENDING, "escape")
			player:hasQuest("code_green"):lock_outer_ward()
			player:newEffect{name="REMOTE_INNER_LOCKDOWN_COUNTDOWN", desc=[[]], type="countdown",
				on_lose = function(self, err)
					local chat = engine.Chat.new("lockdown", npc, player)
					chat:invoke("decontamination")
				end,
			}
			player:setEffect(player.EFF_REMOTE_INNER_LOCKDOWN_COUNTDOWN, 10, {})
		end,
		}
	}
}

newChat{ id="decontamination",
	text = [[#LIGHT_GREEN#The inner ward doors slam shut followed by the PA system again.  #WHITE#"Decontamination procedure initiated, complete in five seconds."]],
	answers = {
		{"Continue.", action=function(npc, player)
			player:hasQuest("code_green"):lock_inner_ward()
			player:hasQuest("code_green"):decontaminate_ward()
			-- Check that the player made it
			player:hasQuest("code_green"):check_escape(player)
			-- Set up the chief of medicine's arrival
			player:newEffect{name="DEBRIEF_COUNTDOWN", desc=[[]], type="countdown",
				on_lose = function(self, err)
					local com = game.zone:makeEntityByName(game.level, "actor", "CHIEF_OF_MEDICINE")
					com:resolve()
					com:resolve(nil, true)
					game.zone:addEntity(game.level, com, "actor")
					local chat = engine.Chat.new("debrief", com, player)
					chat:invoke()
				end
			}
			player:setEffect(player.EFF_DEBRIEF_COUNTDOWN, 5, {})
		end
		},
	}
}

return "welcome"